<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <!-- <a-col :span="24">
            <a-form-model-item label="周会标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weeklyMeetTitle">
              <a-input v-model="model.weeklyMeetTitle" placeholder="请输入周会标题" readOnly></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="待办事项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="representation">
              <a-textarea v-model="model.representation" rows="4" placeholder="请输入待办事项" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预估时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="estimatedTime">
              <j-date placeholder="请选择预估时间" v-model="model.estimatedTime" style="  width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="实际完成时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actualCompletionTime">
              <j-date placeholder="请选择实际完成时间" v-model="model.actualCompletionTime" :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="执行人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="executor">
              <a-input @focus="executorFocus" v-model="model.executor" placeholder="请输入执行人"  ></a-input>
              <!-- <a-select @focus="isExecutor" style="width: 100%" placeholder="请选择执行人"
                v-model="model.executor" allowClear>
                <a-select-option v-for="(item, index) in executors" :key="index" :value="item.realname">
                  {{ item.realname }}
                </a-select-option>
              </a-select> -->
            </a-form-model-item>
            
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最后截止时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deadline">
              <j-date placeholder="请选择最后截止时间" v-model="model.deadline" :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classification">
              <a-select placeholder="请选择分类" style="width: 100%" v-model="model.classification" allowClear>
                <a-select-option value="运维">
                  运维
                </a-select-option>
                <a-select-option value="开发">
                  开发
                </a-select-option>
                <a-select-option value="市场部">
                  市场部
                </a-select-option>
                <a-select-option value="采购部">
                  采购部
                </a-select-option>
                <a-select-option value="总经办">
                  总经办
                </a-select-option>
                <a-select-option value="行政部">
                  行政部
                </a-select-option>
                <a-select-option value="人力资源">
                  人力资源
                </a-select-option>
                <a-select-option value="PMC">
                  PMC
                </a-select-option>
                <a-select-option value="仓库">
                  仓库
                </a-select-option>
                <a-select-option value="生产">
                  生产
                </a-select-option>
                <a-select-option value="品质">
                  品质
                </a-select-option>
                <a-select-option value="设计">
                  设计
                </a-select-option>
                <a-select-option value="其它">
                  其它
                </a-select-option>
              </a-select>
              <!-- <a-input v-model="model.classification" placeholder="请输入分类（运维、开发、其它）"></a-input> -->
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行状态" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="executionStatus">
              <!-- <a-input v-model="model.executionStatus" placeholder="请输入执行状态（未开始、执行中、已完成）"></a-input> -->
              <a-select placeholder="请选择执行状态" style="width: 100%" v-model="model.executionStatus" allowClear>
                <a-select-option value="未开始">
                  未开始
                </a-select-option>
                <a-select-option value="执行中">
                  执行中
                </a-select-option>
                <a-select-option value="已完成">
                  已完成
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'WeeklyReportFeedbackForm',
  components: {
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      executors:{

      },
      model: {
        executor:localStorage.getItem('userInfo')?JSON.parse(localStorage.getItem('userInfo')).realname:''
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
      },
      url: {
        add: "/ch/weeklyReportFeedback/add",
        edit: "/ch/weeklyReportFeedback/edit",
        queryById: "/ch/weeklyReportFeedback/queryById",
        queryLoginUsersByDeptId:'/ch/weeklyReportFeedback/queryLoginUsersByDeptId'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    // if (localStorage.getItem('generateWeeklyTitle') != '') {
    //   this.model.weeklyMeetTitle = window.localStorage.getItem('generateWeeklyTitle')
    //                 // this.queryParam.itemName = window.localStorage.getItem('data')
    //                 console.log("generateWeeklyTitle",window.localStorage.getItem('generateWeeklyTitle'));
    //             } 
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
   
  },
  methods: {
    isExecutor(){
      getAction(this.url.queryLoginUsersByDeptId).then((res) => {
                console.log("queryLoginUsersByDeptId:", res);
                this.executors = res.result
            })
    },
    executorFocus(){

    },
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>